#include <iostream>
#include "../../common/detail.hpp"
#include "../../client/rpc_client.hpp"

void subCallBack(const std::string topic_name, const std::string &msg){
    std::cout << "收到订阅的 " << topic_name << " 主题推送过来的消息: " << msg << std::endl;
}

int main(){
    myrpc::initLoggers();

    auto sub_client = std::make_shared<myrpc::client::TopicClient>("127.0.0.1", 28080);
    std::string topic_name = "HELLO";
    bool ret = sub_client->topicCreate(topic_name);
    if (ret == false){
        myrpc::client_logger->ERROR("创建主题失败!");
        return 1;
    }
    sub_client->topicSubscribe(topic_name, subCallBack);
    myrpc::client_logger->INFO("正常调用订阅操作!");
    // sub_client->topicCancel(topic_name);
    // myrpc::client_logger->INFO("正常调用取消订阅!");
    std::this_thread::sleep_for(std::chrono::seconds(20));
    sub_client->shutdown();
    mylog::shutdown();
    return 0;
}